package cn.doitedu.day03.oo

/**
 * 辅助构造器，是对java主构造器的扩展
 */
class Teacher private(val name: String) {

  var gender: String = _
  var age: Int = _

  //定义辅助构造器（方法）
  def this(name: String, gender: String) {
    //辅助构造器第一行，一定要先调用主构造器,或者其他辅助构造器
    this(name)
    this.gender = gender
  }

  private def this(name: String, gender: String, age: Int) {
    //    this(name)
    //    this.gender = gender
    //    this.age = age
    this(name, gender)
    this.age = age
  }

}

object Teacher {

  def main(args: Array[String]): Unit = {

    val teacher = new Teacher("laozhao")
    val teacher2 = new Teacher("laozhao", "male")

  }

}


object TeacherTest {

  def main(args: Array[String]): Unit = {

    //私有的构造器，只能在伴生对象中使用
    //val teacher = new Teacher("laozhao")

    val t2 = new Teacher("tom", "male")

    //private def this私有的辅助构造方法
    //val t3 =  new Teacher("tom", "male", 10)

  }

}

